<?php
/**
 * Created by PhpStorm.
 * User: HP_USER
 * Date: 2018/9/19
 * Time: 13:51
 */

namespace messenger;

class Messenger
{

    private $name = '18615754304';

    private $pwd = 'D6D21E54600CDBD684ED64D8A402';

    private $content = '';

    private $mobile = '';

    private $sign = '';

    private $type = 'pt';

    private $argv = [];

    public function __construct()
    {
        $this->argv = [
            'name' => $this->name,
            'pwd' => $this->pwd,
            'sign' => $this->sign,
            'type' => $this->type
        ];
    }

    public function sendMsg($mobile )
    {
        $flag = 0;
        $params = '';//要post的数据
        $verify = rand(123456, 999999);//获取随机验证码
        $this->argv['mobile'] = $this->mobile = $mobile;
        $this->argv['content'] = $this->content = '【大荣荟】短信验证码为：' . $verify . '，请勿将验证码提供给他人 ⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄。';
        foreach ($this->argv as $key => $value) {
            if ($flag != 0) {
                $params .= "&";
            }
            $params .= $key . "=";
            $params .= urlencode($value);// urlencode($value);
            $flag = 1;
        }
        $url = "http://web.cr6868.com/asmx/smsservice.aspx?" . $params; //提交的url地址
        $res=file_get_contents($url);
        $con = substr($res, 0, 1);  //获取信息发送后的状态
        return ['code'=>$con,'data'=>$verify];
    }

    public  function msgSend($mobile,$msg)
    {
        $flag = 0;
        $params = '';//要post的数据
        $verify = rand(123456, 999999);//获取随机验证码
        $this->argv['mobile'] = $this->mobile = $mobile;
        $this->argv['content'] = $msg;
        foreach ($this->argv as $key => $value) {
            if ($flag != 0) {
                $params .= "&";
            }
            $params .= $key . "=";
            $params .= urlencode($value);// urlencode($value);
            $flag = 1;
        }
        $url = "http://web.cr6868.com/asmx/smsservice.aspx?" . $params; //提交的url地址
        $res=file_get_contents($url);
        $con = substr($res, 0, 1);  //获取信息发送后的状态
        return ['code'=>$con,'data'=>$verify];
    }

}